﻿@section header{

}
<div class="ui-layout" id="layout" style="height: 100%; width: 100%;">
    <div class="ui-layout-west">
        <div id="itemTree"></div>
    </div>
    <div class="ui-layout-center">
        <div class="topPanel">
            <div class="toolbar">
                <div class="btn-group">
                    <a class="btn btn-primary" onclick="$.reload()"><span class="glyphicon glyphicon-refresh"></span></a>
                </div>
                <div class="btn-group">

                    <a id="NF-add" authorize="yes" class="btn btn-primary dropdown-text" onclick="btn_add()"><i class="fa fa-plus"></i>新建字典</a>
                    <a class="btn btn-primary dropdown-toggle" data-toggle="dropdown"><span class="caret"></span></a>
                    <ul class="dropdown-menu pull-right">
                        <li><a id="NF-BatchAdd" authorize="yes" onclick="btn_BatchAdd()" href="javascript:void()">批量新建字典</a></li>
                        <li><a id="NF-itemstype" authorize="yes" onclick="btn_itemstype()" href="javascript:void()">分类管理</a></li>
                    </ul>
                </div>
                <div class="operate">
                    <ul class="nav nav-pills">
                        <li class="first">已选中<span>1</span>项</li>
                        <li><a id="NF-edit" authorize="yes" onclick="btn_edit()"><i class="fa fa-pencil-square-o"></i>修改字典</a></li>
                        <li><a id="NF-delete" authorize="yes" onclick="btn_delete()"><i class="fa fa-trash-o"></i>删除字典</a></li>
                        <li><a id="NF-Details" authorize="yes" onclick="btn_details()"><i class="fa fa-search-plus"></i>查看字典</a></li>
                    </ul>
                    <a href="javascript:;" class="close"></a>
                </div>
                <script>$('.toolbar').authorizeButton()</script>
            </div>
            <div class="search">
                <table>
                    <tr>
                        <td>
                            <div class="input-group">
                                <input id="txt_keyword" type="text" class="form-control" placeholder="名称/编号" style="width: 200px;">
                                <span class="input-group-btn">
                                    <button id="btn_search" type="button" class="btn  btn-primary"><i class="fa fa-search"></i></button>
                                </span>
                            </div>
                        </td>
                    </tr>
                </table>
            </div>
        </div>
        <div class="gridPanel">
            <table id="gridList"></table>
        </div>
    </div>
</div>
@section scripts{
    <script>
        $(function () {
            $('#layout').layout();
            treeView();
            gridList();
        });
        function treeView() {
            $("#itemTree").treeview({
                url: "/rbac/ItemsType/GetTreeJson",
                method: "POST",
                onnodeclick: function (item) {
                    $("#txt_keyword").val('');
                    $('#btn_search').trigger("click");
                }
            });
        }
        function gridList() {
            var $gridList = $("#gridList");
            $gridList.dataGrid({
                height: $(window).height() - 96,
                colModel: [
                    { label: "主键", name: "ID", hidden: true, key: true },
                    {
                        label: '排序', name: 'OrderBy', width: 100, align: 'left',
                        formatter: function (cellvalue, options, rowObject) {
                            var keyId = rowObject.ID;
                            return "<input type='text' name='OrderBy[" + keyId + "]' autocomplete='off' style='width: 50px; height: 20px;' onchange='update_field(\"" + keyId + "\",this.value)' value=" + cellvalue + " />";
                        }
                    },
                    { label: '名称', name: 'Name', width: 150, align: 'left' },
                    { label: '编号', name: 'EndCode', width: 150, align: 'left' },
                    {
                        label: "默认", name: "IsDefault", width: 60, align: "center",
                        formatter: function (cellvalue) {
                            return cellvalue == true ? "<i class=\"fa fa-toggle-on\"></i>" : "<i class=\"fa fa-toggle-off\"></i>";
                        }
                    },
                    {
                        label: "有效", name: "Status", width: 100, align: "center",
                        formatter: function (cellvalue, options, rowObject) {
                            var keyId = rowObject.ID;
                            return cellvalue == 0 ? "<i onclick='Switch(\"" + keyId + "\")' class=\"fa fa-toggle-on\"></i>" : "<i onclick='Switch(\"" + keyId + "\")' class=\"fa fa-toggle-off\"></i>";
                        }
                    },
                    { label: "备注", name: "Description", index: "Description", width: 200, align: "left", sortable: false }
                ],
                rowNum: 20,
                rowList: [20, 50, 100],
                pager: '#gridPager',
                sortname: 'OrderBy',
                sortorder: "asc",
                viewrecords: true,
                autowidth: true,
                multiselect: true,
                loadComplete: function () {
                    $('.ui-jqgrid-bdiv').scrollTop(0);
                    setTimeout(function () { btn_tc(); });
                }
            });
            $("#btn_search").click(function () {
                $gridList.jqGrid('setGridParam', {
                    url: "/rbac/ItemsData/GetItemDetailGridJson",
                    postData: { itemId: $("#itemTree").getCurrentNode().id, keyword: $("#txt_keyword").val() },
                }).trigger('reloadGrid');
            });
        }
        function btn_BatchAdd() {
            var itemId = $("#itemTree").getCurrentNode().id;
            var itemName = $("#itemTree").getCurrentNode().text;
            if (!itemId) {
                return false;
            }
            $.modalOpen({
                id: "Form",
                title: itemName + " 》新增字典",
                url: "/rbac/ItemsData/BatchAdd?itemId=" + itemId,
                width: "450px",
                height: "350px",
                callBack: function (iframeId) {
                    top.frames[iframeId].submitForm();
                }
            });
        }
        function btn_add() {
            try {
                var itemId = $("#itemTree").getCurrentNode().id;
                var itemName = $("#itemTree").getCurrentNode().text;
                if (!itemId) {
                    return false;
                }
            } catch (e) {
                return false;
            }

            $.modalOpen({
                id: "Form",
                title: itemName + " 》新增字典",
                url: "/rbac/ItemsData/Form?itemId=" + itemId,
                width: "450px",
                height: "350px",
                callBack: function (iframeId) {
                    top.frames[iframeId].submitForm();
                }
            });
        }
        function btn_edit() {
            var itemName = $("#itemTree").getCurrentNode().text;
            var keyValue = $("#gridList").jqGridRowValue().ID;
            $.modalOpen({
                id: "Form",
                title: itemName + " 》修改字典",
                url: "/rbac/ItemsData/Form?keyValue=" + keyValue,
                width: "450px",
                height: "350px",
                callBack: function (iframeId) {
                    top.frames[iframeId].submitForm();
                }
            });
        }
        function btn_delete() {
            $.deleteForm({
                url: "/rbac/ItemsData/DeleteForm",
                param: { keyValue: $("#gridList").jqGridRowValue().ID },
                success: function () {
                    $("#gridList").resetSelection();
                    $("#gridList").trigger("reloadGrid");
                }
            })
        }
        function btn_details() {
            var keyValue = $("#gridList").jqGridRowValue().ID;
            $.modalOpen({
                id: "Details",
                title: "查看字典",
                url: "/rbac/ItemsData/Details?keyValue=" + keyValue,
                width: "450px",
                height: "470px",
                btn: null,
            });
        }
        function btn_itemstype() {
            $.modalOpen({
                id: "ItemsType",
                title: "字典分类",
                url: "/rbac/ItemsType/Index",
                width: "800px",
                height: "550px",
                btn: null,
            });
        }
    </script>
}